package Ep05_StackAndQueue._0020;

import java.util.Stack;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/4/12 10:09
 * 说明：
 */

public class Mine {
    public boolean isValid(String s) {
        char ch;
        Stack<Character> quoter = new Stack<>();

        for (int i = 0; i < s.length(); i++) {
            ch = s.charAt(i);
            if (ch == '('){
                quoter.push(')');
            } else if (ch == '[') {
                quoter.push(']');
            } else if (ch == '{'){
                quoter.push('}');
            } else if (quoter.isEmpty() || ch != quoter.pop()) {
                return false;
            }
        }
        return quoter.isEmpty();
    }
}
